<template>
	<view>
		<view style="text-align: center;">
			<image src="/static/notice.png" mode="widthFix" style="width: 100%"></image>
			<view style="font-weight: bold; font-size: 35rpx; color: #7AA2ED;">{{message}}</view>
		</view>
	</view>
</template>

<script>
	import * as api from '@/api/staff'
	import storage from '@/utils/storage'
	import * as app from '@/utils/app'
	export default {
		data() {
			return {
				message: '',
				scene: {}
			};
		},
		onLoad(option) {
			this.scene = app.parseScene(option.scene);
		},
		onShow() {
			if (storage.get('authToken') == false) {
				uni.navigateTo({ url: '/pages/user/login' })
			} else {
				this.binding();
			}
		},
		methods: {
			binding: function () {
				var that = this;
				api.binding({
					activityId: this.scene.activityId ?? ''
				}).then(res => {
					var second = 3;
					this.message = res.msg + '，' + second + '秒后跳转到活动页';
					let timerId = setInterval(function () {
						if (second > 0) {
							second --;
						}
						that.message = res.msg + '，' + second + '秒后跳转到活动页';
						if (second <= 0) {
							clearInterval(timerId);
							uni.redirectTo({ url: '/pages/activity/index?activityId=' + that.scene.activityId ?? '' });
						}
					}, 1000)
				}).catch(res => {
					this.message = res.errMsg;
				});
			}
		}
	}
</script>

<style>
</style>